<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
require_once("lib/my_library.php");
//Includes
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Unit1 extends Page
{
       public $JTReminders = null;
       public $btnSearch = null;
       public $edtSearch = null;
       public $Image3 = null;
       public $JTSiteTheme1 = null;
       function btnSearchClick($sender, $params)
       {
       redirect('all_reminder.php?company_id='.$_SESSION['company_id']);


       }

       function edtSearchJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edtSearch').value = '';
       <?php

       }

       function JTRemindersShow($sender, $params)
       {
        $my_lib = new my_library();
        $query_check = "select * from veh_reminder_tbl where company_id='".$_SESSION['company_id']."' and (due_hours like '%".$this->edtSearch->Text."%'
        or due_date like '%".$this->edtSearch->Text."%'
        or type like '%".$this->edtSearch->Text."%'
        or description like '%".$this->edtSearch->Text."%'
        or status2 like '%".$this->edtSearch->Text."%') order by reminder_id ASC";
        $result_check = mysql_query($query_check)or die(mysql_error());
        $row_check = mysql_fetch_array($result_check);

        $arr = array();
        while($row_check = mysql_fetch_array($result_check))
          {
            $query_od = "select * from vehicle_tbl where company_id='".$_SESSION['company_id']."' and vehicle_id='".$row_check['vehicle_id']."'";
            $result_od = mysql_query($query_od)or die(mysql_error());
            $row_od = mysql_fetch_array($result_od);

            $vehicle_id = $row_check['vehicle_id'];
            $due_date = $row_check['due_date'];
            $curr_date = date("Y-m-d");
            $odometer = $row_check['due_hours'];
            $curr_od = $row_od['curr_tracking_value'];
            $track_by = $row_check['schedule_by'];
            $prev_od = $row_od['tracking_value'];

            if($due_date!=null || $due_date!='')
            $days_diff = $my_lib->daysDifference($due_date, $curr_date);

            $odometer_diff = $odometer - $curr_od;
            $mileage = $curr_od - $prev_od;


            //die(var_dump($row_check));
            //if($track_by=='Both' && ($curr_date>=$due_date || $curr_od>=$odometer))
            if($track_by=='Both')
            {
               if($days_diff>14 && $odometer_diff>1000)
               $gauge = "<img src='image/gauge_green.png'/>";
               if(($days_diff<=14 && $days_diff>7) || ($odometer_diff<=1000 && $odometer_diff>250))
               $gauge = "<img src='image/gauge_yellow.png'/>";
               if($days_diff<=7 || $odometer_diff<=250)
               $gauge = "<img src='image/gauge_red.png'/>";

               if($row_check['status2']=="Complete")
               {
               $color = "Silver";
               }

               if($row_check['status2']=="Pending")
               {
               $color = "Black";
               }

               $arr[] = array(
               'Vehicle' => $row_od['veh_num'].' '.$row_od['manufacturer_name'].' '.$row_od['model_name'],
               'Due at(km/hrs)' => "<p style='color:".$color."'>".$row_check['due_hours']."</p>",
               'Due by' => "<p style='color:".$color."'>".$row_check['due_date']."</p>",
               'Mileage(km)' =>"<p style='color:".$color."'>".$mileage."</p>",
               'Type' => "<p style='color:".$color."'>".$row_check['type']."</p>",
               'Reminder Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'Status' => "<p style='color:".$color."'>".$row_check['status2']."</p>",
               'Alert Meter' => $gauge
               );
            }
            //if($track_by=='Hours/Km' && $curr_od>=$odometer)
            if($track_by=='Hours/Km')
            {
               if($odometer_diff>1000)
               $gauge = "<img src='image/gauge_green.png'/>";
               if($odometer_diff<=1000 && $odometer_diff>250)
               $gauge = "<img src='image/gauge_yellow.png'/>";
               if($odometer_diff<=250)
               $gauge = "<img src='image/gauge_red.png'/>";

               if($row_check['status2']=="Complete")
               {
               $color = "Gray";
               }

               if($row_check['status2']=="Pending")
               {
               $color = "Black";
               }

               $arr[] = array(
               'Vehicle' => $row_od['veh_num'].' '.$row_od['manufacturer_name'].' '.$row_od['model_name'],
               'Due at(km/hrs)' => "<p style='color:".$color."'>".$row_check['due_hours']."</p>",
               'Due by' => "<p style='color:".$color."'>".$row_check['due_date']."</p>",
               'Mileage(km)' =>"<p style='color:".$color."'>".$mileage."</p>",
               'Type' => "<p style='color:".$color."'>".$row_check['type']."</p>",
               'Reminder Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'Status' => "<p style='color:".$color."'>".$row_check['status2']."</p>",
               'Alert Meter' => $gauge
               );
            }
            //if($track_by=='Date' && $curr_date>=$due_date)
            if($track_by=='Date')
            {
               if($days_diff>14)
               $gauge = "<img src='image/gauge_green.png'/>";
               if($days_diff<=14 && $days_diff>7)
               $gauge = "<img src='image/gauge_yellow.png'/>";
               if($days_diff<=7)
               $gauge = "<img src='image/gauge_red.png'/>";

               if($row_check['status2']=="Complete")
               {
               $color = "Gray";
               }

               if($row_check['status2']=="Pending")
               {
               $color = "Black";
               }

               $arr[] = array(
               'Vehicle' => $row_od['veh_num'].' '.$row_od['manufacturer_name'].' '.$row_od['model_name'],
               'Due at(km/hrs)' => "<p style='color:".$color."'>".$row_check['due_hours']."</p>",
               'Due by' => "<p style='color:".$color."'>".$row_check['due_date']."</p>",
               'Mileage(km)' =>"<p style='color:".$color."'>".$mileage."</p>",
               'Type' => "<p style='color:".$color."'>".$row_check['type']."</p>",
               'Reminder Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'Status' => "<p style='color:".$color."'>".$row_check['status2']."</p>",
               'Alert Meter' => $gauge
               );
            }
          }
            //die(var_dump($arr));
            $this->JTReminders->setCellData($arr);

       }
}
global $application;

global $Unit1;

//Creates the form
$Unit1=new Unit1($application);

//Read from resource file
$Unit1->loadResource(__FILE__);

//Shows the form
$Unit1->show();

?>